#!/bin/bash
# Author : chun.yang
# Desc   : 各个系统密码valut初始化，##{cipher}后紧跟加密密文，
#密文使用curl -u msxf:msxf 10.16.30.85:8888/encrypt -d mysql@123 获得
#同一个系统多个key之间使用如下格式：\key1=value1 \key2=value2

APP_USER=finance
CONFIG_SERVER_U_P=msxf:msxf ##线上配置中访问用户密码 默认msxf/msxf
CONFIG_SERVER_HOST=10.16.30.85:8888 ##线上config-server部署ip:port
VALUT=/home/finance/App/vault/vault ##线上安装路径

##调用配置中心加密明文
CMC_DB_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d mysql@123`  ##修改线为上密码
CMC_MQ_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d guest` ##修改线为上密码

CCA_DB_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d mysql@123` ##修改线为上密码
CCA_FTP_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d cca` ##修改线为上密码

ICMS_DB_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d mysql@123` ##修改线为上密码
ICMS_FTP_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d static` ##修改线为上密码

IFS_DB_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d mysql@123` ##修改线为上密码
IFS_FTP_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d HUvueMGWg92y8SSN` ##修改线为上密码

TMSTOOLS_DB_PWD=`curl -u $CONFIG_SERVER_U_P $CONFIG_SERVER_HOST/encrypt -d mysql@123` ##修改线为上密码

##登录授权
su $APP_USER -c "$VALUT auth 7a686d33-4f40-85de-e3a5-e3899011a874"  ##需要修改为线上vault创建的token

##cmc init   
su $APP_USER -c "$VALUT write secret/cmc/online \db.password={cipher}$CMC_DB_PWD \spring.rabbitmq.password={cipher}$CMC_MQ_PWD"

##cca init
su $APP_USER -c "$VALUT write secret/cca/online \db.password={cipher}$CCA_DB_PWD \ftp.password={cipher}$CCA_FTP_PWD"

##icms init
su $APP_USER -c "$VALUT write secret/icms/online \db.password={cipher}$ICMS_DB_PWD \upload.ftp.pwd={cipher}$ICMS_FTP_PWD"

##filesystem init
su $APP_USER -c "$VALUT write secret/filesystem/online \db.password={cipher}$IFS_DB_PWD \ftp.password={cipher}$IFS_FTP_PWD"

##tmstools init
su $APP_USER -c "$VALUT write secret/tmstools/online db.password={cipher}$TMSTOOLS_DB_PWD"
